#lang racket

(require racket/match)

(require "parser.scm")
(require "debug.scm")

(require "utilities.scm")
(require "box.scm")
(require "syntax.scm")
(require "environment.scm")
(require "resolve.scm")
(require "interpret.scm")

;;; scheme builtins
;;

(define-syntax define-builtins
  (syntax-rules ()
    ((define-builtins builtins <name> ...)
     (define builtins
       `((<name> . ,(box <name>)) ...)))))

(define-builtins builtins
  cons car cdr
  box box-value set-box-value!
  = eq? equal? not
  + - * /
  display newline print

  ;; predicates from R5RS  
  boolean?
  pair?
  symbol?
  number?
  char?
  string?
  vector?
  procedure?
  )

;;; main driver
;;

(define (check file)
  (print (list 'processing file))
  (let* ((prg (parse-file file))
	 (cod (resolve-program prg builtins)))
    (print (list 'code cod))
    (print (list 'raw-code))
    (for-each print (syx->datum cod))))

(define (go file)
  (let* ((prg (parse-file file))
	 (cod (resolve-program prg builtins))
	 (env (env builtins)))
    (interpret-program cod env)))
